<template>
  <div class="table-box">
    <table-tools :columns.sync="columns" @refresh="refreshTable"/>
    <a-table
      :columns="columns"
      :data-source="data"
      :loading="tableLoading"
      bordered
    >
      <template #action>
        <a>View</a>
      </template>
    </a-table>
    <a-divider orientation="left">
      <strong style="color: red; font-size: 30px;">直接看这个例子，下面是子组件：</strong>
      <test-vuex-watch/>
    </a-divider>
  </div>
</template>

<script>
import TableTools from '@/components/TableTools/TableTools'
import TestVuexWatch from '@/components/TestVuexWatch'

const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    checked: true
  },
  {
    title: 'Cash Assets',
    dataIndex: 'money',
    checked: true
  },
  {
    title: 'Address',
    dataIndex: 'address',
    checked: true
  },
  {
    title: 'Action',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' }
  }
]

const data = [
  {
    key: '1',
    name: 'John Brown',
    money: '￥300,000.00',
    address: 'New York No. 1 Lake Park'
  },
  {
    key: '2',
    name: 'Jim Green',
    money: '￥1,256,000.00',
    address: 'London No. 1 Lake Park'
  },
  {
    key: '3',
    name: 'Joe Black',
    money: '￥120,000.00',
    address: 'Sidney No. 1 Lake Park'
  },
  {
    key: '4',
    name: 'Jim Green',
    money: '￥1,256,000.00',
    address: 'London No. 1 Lake Park'
  },
  {
    key: '5',
    name: 'Joe Black',
    money: '￥120,000.00',
    address: 'Sidney No. 1 Lake Park'
  },
  {
    key: '6',
    name: 'Jim Green',
    money: '￥1,256,000.00',
    address: 'London No. 1 Lake Park'
  },
  {
    key: '7',
    name: 'Joe Black',
    money: '￥120,000.00',
    address: 'Sidney No. 1 Lake Park'
  }
]
export default {
  name: 'TableToolsDemo',
  components: { TestVuexWatch, TableTools },
  data () {
    return {
      columns,
      data,
      tableLoading: false
    }
  },
  computed: {
    globalSelectVal () {
      return this.$store.state.globalSelectVal
    }
  },
  watch: {
    globalSelectVal (val) {
      this.$message.info(`父组件获取到的值为：${val}，你可以在该代码下执行逻辑`)
    }
  },
  methods: {
    refreshTable () {
      this.tableLoading = true
      setTimeout(() => {
        this.tableLoading = false
      }, 1000)
    }
  }
}
</script>

<style scoped>
.table-box {
  padding-top: 50px;
}
</style>
